$(function() {
	//引入头部部分
	$("header").load("header_con.html");
	//引入侧拉列表部分
	$("article").load("article_list.html",function(){
		$(".my_yihe_tickets").css({
			"color":"rgb(229, 89, 25)",
			"textDecoration":"underline"
		})
	});
	//引入尾部的部分
	$("footer").load("footer.html");
	//<-------------引入分页符------------------->
	$(".paginate").load("jPaginate.html")
	//<-------------立即支付按钮的点击事件------------------->
	// 创建对象存储在localStorage中
	var recharge_obj = {
		// 订单时间
		order_time:[],
		// 订单编号
		order_num:[],
		// 充值金额
		order_val:[],
		// 账户余额
		account_rest:[]
	};
	// 先判断localStorage中是否有数据，有数据则显示在当前页面上
	if (localStorage.recharge_json) {
		// 将存起来的对象，赋值给当前的对象
		recharge_obj = JSON.parse(localStorage.recharge_json);
		for (var i = 0; i < recharge_obj.order_time.length; i++) {
			// 创建对象
			var tr = $('<tr><td>'+recharge_obj.order_time[i]+'</td><td class="red_font">'+recharge_obj.order_num[i]+'</td><td class="red_font"><span>￥</span><span>'+recharge_obj.order_val[i]+'</span><span>元</span></td><td><span>￥</span><span>'+recharge_obj.account_rest[i]+'</span><span>元</span></td></tr>');
			$(".first_tr").after(tr);
		}
		$(".account_rest").text(recharge_obj.account_rest[recharge_obj.order_num.length - 1]);
	}
	$("#rechargeBtn").click(function() {
		// 将充值内容，存储起来
		if ($("#rechargeText").val() == "") {
			alert("充值金额不能为空");
		}else{
			recharge_obj.order_time.push(getNowFormatDate());
			if (recharge_obj.order_num.length == 0) {
				recharge_obj.order_num.push(4120000000);
			}else{
				recharge_obj.order_num.push(recharge_obj.order_num[recharge_obj.order_num.length - 1] + 1);
			}
			recharge_obj.order_val.push($("#rechargeText").val());
			recharge_obj.account_rest.push(parseInt($(".account_rest").text()) + parseInt($("#rechargeText").val()));
			//将对象转化为JSON字符串存起来
			localStorage.recharge_json = JSON.stringify(recharge_obj);
			window.location = "my_recharge_pay.html";
		}
	})
	//<-----------------格式化日期----------------->
	function getNowFormatDate() {
		var date = new Date();
		var seperator1 = "-";
		var seperator2 = ":";
		var month = date.getMonth() + 1;
		var strDate = date.getDate();
		if(month >= 1 && month <= 9) {
			month = "0" + month;
		}
		if(strDate >= 0 && strDate <= 9) {
			strDate = "0" + strDate;
		}
		var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
			" " + date.getHours() + seperator2 + date.getMinutes() +
			seperator2 + date.getSeconds();
		return currentdate;
	}
})